package remotetask;

import org.quartz.*;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 自定义任务
 * @Author xiewenlong
 * @Date 2018/11/20 13:35
 * DisallowConcurrentExecution 禁止并发执行（当一个任务没有执行完，时间到了又去执行新的任务）
 * PersistJobDataAfterExecution 处理完后通知 Quartz 参数更新了，防止并发时使用了原先的旧数据
 */
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class RemoteTask extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        before();
        System.out.println("RemoteTask execute......" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        after();
    }

    public void before(){
        System.out.println("before");
    }

    public void after(){
        System.out.println("after");
    }

}
